// rs_anwser/pages/mutilple_exam/mutilple.js

var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isStarted: false,
    totalScore: 0,//考试得分
    isExamFinished: false,
    current: 0,
    total: 160,
    remainTime: 0,
    minutes:90,
    btnTitle: '下一题',
    subjectList: [
    
    ]
  
  },

  startexam:function(){
     this.setData({'isStarted':true});
     var me = this;
     app.util.request({
       url: "entry/wxapp/getExamSubjects",
       data: {
         m: "rs_anwser",
         subjectType: 'mutilple'
       },
       success: function (data) {

         me.setData({
           subjectList: data.data.data,
           total: data.data.data.length
         })
       }
     })
  },

  updateSubjectList:function(data){
    console.log(data);
     this.setData({subjectList:data});
  },


  updateCurrent: function (data) {
    this.setData({ current: data.detail });
  },

  updateRemainTime: function (e) {
    this.setData({ remainTime: e.detail.remainTime });

  },

  updateTotalScore: function (e) {
    console.log(e);
    this.setData({ totalScore: e.detail, isExamFinished: true });
  },

  /**
   * 选择题目选项
   */
  selectOption: function (e) {


      var subject = getApp().subjectPage.getCurrentSubject(this); 
      var index = e.currentTarget.dataset.index;
      var options = subject.options;
      var resultClass = typeof (options[index]['resultClass']) == 'undefined' ? '' : options[index]['resultClass']; 
      var selectOption = typeof (subject.selectOption) == 'undefined'?[]:subject.selectOption;
      var label = options[index]['label'];
      if(resultClass==''){
        resultClass = 'option-select';
        selectOption.push(label);
      }else{
        resultClass = '';
        selectOption.splice(selectOption.indexOf(label)-1,1);
      }

      options[index]['resultClass']=resultClass;

       

      subject.options = options;
      subject.selectOption = selectOption;
      getApp().subjectPage.updateCurrentSubject(this,subject);
    
  },

  updateRemainTime:function(e){
     this.setData({remainTime:e.detail.remainTime});

  },

  updateTotalScore: function (e) {
    console.log(e);
    this.setData({ totalScore: e.detail, isExamFinished: true });
  },
  changeSubject: function (e) {
    if (e.detail.current == this.data.subjectList.length - 1) {
      this.setData({ btnTitle: '交卷' });
    } else if (e.detail.current == this.data.subjectList.length - 2) {
      this.setData({ btnTitle: '下一题' });
    }
    this.setData({ current: e.detail.current });

  },

 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var me = this;
    app.util.request({
      url: 'entry/wxapp/getExamSetting',
      data: {
        m: 'rs_anwser',
        subjectType: 'mutilple'
      },
      success: function (data) {

        var temp = data.data.data;
        var examSetting = { duration: temp.duration, title: temp.title, totalScore: temp.setting.mutilple.total_score, perScore: temp.setting.mutilple.per_score };
        me.setData({ examSetting: examSetting });

        me.setData({ 'minites': temp.duration, 'remainTime': getApp().subjectPage.getRemainTime(temp.duration * 60) });


      }
    })


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})